home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / SanFrancisco_1989 / SF-Devcon89.2 / Workbench / AppMenuItem / appmenuitem.c
Encoding:
C/C++ Source or Header  |  1992-08-27  |  3.0 KB  |  124 lines

  1. /*
  2.     Code to test AppMenuItem feature of Workbench.
  3. */
  4.  
  5. #include <intuition/intuition.h>
  6. #include <workbench/startup.h>
  7. #include "workbench/workbench.h"
  8.  
  9. #define INTUITIONNAME    "intuition.library"
  10. #define WORKBENCHNAME    "workbench.library"
  11.  
  12. struct IntuitionBase *IntuitionBase = NULL;
  13. struct WorkbenchBase *WorkbenchBase = NULL;
  14.  
  15. struct NewWindow nw = {
  16.     0, 0,        /* leftedge, topedge */
  17.     160,50,        /* width, height */
  18.     -1, -1,        /* DetailPen, BlockPen */
  19.     CLOSEWINDOW,        /* IDCMP flags */
  20.     WINDOWCLOSE|WINDOWDRAG,        /* flags */
  21.     NULL,        /* FirstGadget */
  22.     NULL,        /* Image */
  23.     "AppMenuItem",    /* Title */
  24.     NULL,        /* Screen */
  25.     NULL,        /* BitMap */
  26.     0, 0,        /* MinWidth, MinHeight */
  27.     0, 0,        /* MaxWidth, MaxHeight */
  28.     WBENCHSCREEN    /* type */
  29. };
  30.  
  31. main(argc, argv)
  32. int argc;
  33. char **argv;
  34. {
  35.     void *OpenLibrary();
  36.     struct MsgPort *CreatePort();
  37.     struct Window *OpenWindow();
  38.     struct IntuiMessage *GetMsg();
  39.     struct AppMenuItem *AddAppMenuItem();
  40.  
  41.     struct MsgPort *msgport = NULL;
  42.     struct Window *win = NULL;
  43.     struct AppMenuItem *ami1 = NULL, *ami2 = NULL;
  44.     struct IntuiMessage *imsg;
  45.     struct AppMessage *amsg;
  46.     struct WBArg *argptr;
  47.     ULONG id = 1, userdata = 0;
  48.     BOOL done = FALSE;
  49.     int i;
  50.  
  51.     printf("ami: enter\n");
  52.     if (!(IntuitionBase = OpenLibrary(INTUITIONNAME, 0))) {
  53.         printf("ami: could not open intuition\n");
  54.         goto err;
  55.     }
  56.     if (!(WorkbenchBase = OpenLibrary(WORKBENCHNAME, 36))) {
  57.         printf("ami: could not open workbench\n");
  58.         goto err;
  59.     }
  60.     if (!(msgport = CreatePort("appmenuitem", 0))) {
  61.         printf("ami: could not createport\n");
  62.         goto err;
  63.     }
  64.     if (!(win = OpenWindow(&nw))) {
  65.         printf("ami: could not openwindow\n");
  66.         goto err;
  67.     }
  68.     printf("ami: calling AddAppMenuItem for ami1...");
  69.     if (!(ami1 = AddAppMenuItem(id, userdata, "appmenuitem1", msgport))) {
  70.         printf("ami: could not addappmenuitem\n");
  71.         goto err;
  72.     }
  73.     printf("ami: calling AddAppMenuItem for ami2...");
  74.     if (!(ami2 = AddAppMenuItem(85, 55, "appmenuitem2", msgport))) {
  75.         printf("ami: could not addappmenuitem\n");
  76.         goto err;
  77.     }
  78.     printf("ami: ok, ami2 = %lx, going to sleep\n", ami2);
  79.     do {
  80.         Wait((1 << win->UserPort->mp_SigBit) |
  81.             (1 << msgport->mp_SigBit));
  82.         while (imsg = GetMsg(win->UserPort)) {
  83.             if (imsg->Class == CLOSEWINDOW) {
  84.                 done = TRUE;
  85.             }
  86.         };
  87.         while (amsg = GetMsg(msgport)) {
  88.             printf("ami: appmsg=%lx, Type=%ld, ID=%ld, UserData=%ld, NumArgs=%ld\n", amsg, amsg->am_Type, amsg->am_ID, amsg->am_UserData, amsg->am_NumArgs);
  89.             argptr = amsg->am_ArgList;
  90.             for (i=0; i<amsg->am_NumArgs; i++) {
  91.                 printf("\targ(%ld): Name='%s', Lock=%lx\n",
  92.                 i, argptr->wa_Name, argptr->wa_Lock);
  93.                 argptr++;
  94.             }
  95.             ReplyMsg(amsg);
  96.         };
  97.     } while (!done);
  98.  
  99.     if (ami1) {
  100.         printf("ami: calling RemoveAppMenuItem for ami1\n");
  101.         RemoveAppMenuItem(ami1);
  102.     }
  103.  
  104.     if (ami2) {
  105.         printf("ami: calling RemoveAppMenuItem for ami2\n");
  106.         RemoveAppMenuItem(ami2);
  107.     }
  108.  
  109. err:
  110.     if (win) {
  111.         CloseWindow(win);
  112.     }
  113.     if (msgport) {
  114.         DeletePort(msgport);
  115.     }
  116.     if (WorkbenchBase) {
  117.         CloseLibrary(WorkbenchBase);
  118.     }
  119.     if (IntuitionBase) {
  120.         CloseLibrary(IntuitionBase);
  121.     }
  122.     printf("ami: exit\n");
  123. }
  124.